package com.d3works.apps.report.engine;

import com.d3works.apps.base.service.ReportingTool;
import com.d3works.exception.D3worksException;
import com.d3works.exception.db.repo.TraceBackRepository;
import com.d3works.inject.Beans;
import com.d3works.report.ReportGenerator;
import java.io.IOException;
import org.eclipse.birt.core.exception.BirtException;

public class EmbeddedReportSettings extends ReportSettings {

  public EmbeddedReportSettings(String rptdesign, String outputName) {

    super(rptdesign, outputName);
  }

  @Override
  public EmbeddedReportSettings generate() throws D3worksException {

    super.generate();

    try {

      final ReportGenerator generator = Beans.get(ReportGenerator.class);

      this.output = generator.generate(rptdesign, format, params, ReportingTool.getCompanyLocale());

      this.attach();

    } catch (IOException | BirtException e) {
      throw new D3worksException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }

    return this;
  }
}
